#include "cpw.h"
#include "ui_cpw.h"

CompetitionPropertesWizard::CompetitionPropertesWizard(QSqlDatabase db, QWidget *parent) :
    QWizard(parent),
    ui(new Ui::CompetitionPropertesWizard),
    dbase(db),
    query(new QSqlQueryModel(this)),
    modelGroups(new QSqlTableModel(this, dbase))
{
    ui->setupUi(this);
    page(0)->setTitle(tr("Competition title"));
    page(0)->setSubTitle(tr("Basic properties and description"));
    ui->actionEmblem_Select_in_database->setIcon(QIcon::fromTheme("folder-image"));
    ui->graphicsViewEmblem->addAction(ui->actionEmblem_Select_in_database);
    ui->actionEmblem_Load_from_file->setIcon(QIcon::fromTheme("insert-image"));
    ui->graphicsViewEmblem->addAction(ui->actionEmblem_Load_from_file);
    page(1)->setTitle(tr("Member access rules"));
    page(1)->setSubTitle(tr("Member age and gender group control"));
    ui->tableViewMemberGroups->addAction(ui->actionMemberGroupAdd);
    ui->actionMemberGroupAdd->setIcon(QIcon::fromTheme("user-group-new"));
    ui->tableViewMemberGroups->addAction(ui->actionMemberGroupRemove);
    ui->actionMemberGroupRemove->setIcon(QIcon::fromTheme("user-group-delete"));
    QAction *actionMemberGroupSeparator = new QAction(this);
    actionMemberGroupSeparator->setSeparator(true);
    ui->actionMemberGroupSelect->setIcon(QIcon::fromTheme("checkbox"));
    ui->tableViewMemberGroups->addAction(actionMemberGroupSeparator);
    ui->tableViewMemberGroups->addAction(ui->actionMemberGroupSelect);
    page(2)->setTitle(tr("Competition structure"));
    page(2)->setSubTitle(tr("Tour list"));
    ui->treeViewCompetitionStruct->addAction(ui->actionAdd_tour);
    ui->actionAdd_tour->setIcon(QIcon::fromTheme("list-add"));
    ui->treeViewCompetitionStruct->addAction(ui->actionRemove_tour);
    ui->actionRemove_tour->setIcon(QIcon::fromTheme("list-remove"));
}


CompetitionPropertesWizard::~CompetitionPropertesWizard()
{
    delete ui;
}

void CompetitionPropertesWizard::showEvent (QShowEvent *event)
{
    modelGroups->setTable("group");
    ui->tableViewMemberGroups->setModel(modelGroups);
    modelGroups->select();
    ui->tableViewMemberGroups->hideColumn(0);
    modelGroups->setHeaderData(1, Qt::Horizontal, tr("Group"));
    modelGroups->setHeaderData(2, Qt::Horizontal, tr("gender"));
    modelGroups->setHeaderData(3, Qt::Horizontal, tr("age min"));
    modelGroups->setHeaderData(4 ,Qt::Horizontal, tr("age max"));
    ui->tableViewMemberGroups->show();
    ui->comboBoxMainJudge->clear();

    ui->comboBoxMainSecretary->clear();


    event->accept();
}

void CompetitionPropertesWizard::on_actionMemberGroupAdd_triggered()
{
    modelGroups->insertRow(modelGroups->rowCount());
}

void CompetitionPropertesWizard::on_actionMemberGroupRemove_triggered()
{
    if (ui->tableViewMemberGroups->currentIndex().isValid()) modelGroups->removeRow(ui->tableViewMemberGroups->currentIndex().row());
}

void CompetitionPropertesWizard::on_actionMemberGroupSelect_triggered()
{

}
